{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Captum Visual Insights for MNIST Classification Model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This Notebook helps you to get started with the Captum Insights..The example covered here is from the MNIST Classifier model used in Torchserve.In order to understand the word importances and attributions when we make an Explanation Request, we use Captum Insights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import captum\n",
    "from captum.attr import visualization as viz\n",
    "import os\n",
    "import logging\n",
    "import numpy as np\n",
    "import json\n",
    "import torch\n",
    "from transformers import AutoTokenizer\n",
    "from PIL import Image\n",
    "from torchvision.transforms import ToTensor\n",
    "from matplotlib.colors import LinearSegmentedColormap"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Create the mar file for the MNIST Classification model and place the artefacts from where you can serve the model. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/bin/sh: 1: torch-model-archiver: not found\r\n"
     ]
    }
   ],
   "source": [
    "!torch-model-archiver --model-name mnist_explain --version 1.0 --model-file serve/examples/image_classifier/mnist/mnist.py --serialized-file serve/examples/image_classifier/mnist/mnist_cnn.pt --handler  serve/examples/image_classifier/mnist/mnist_handler.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2"
     ]
    }
   ],
   "source": [
    "#curl request to make a Prediction Request\n",
    "!curl -H \"Content-Type: application/json\" --data @examples/image_classifier/mnist/mnist_ts.json http://127.0.0.1:8080/predictions/mnist_explain"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Make a Explanation response for the bert model by specifying body in the service envelope in the config.properties file, like below:\n",
    "\n",
    "```\n",
    "service_envelope=body\n",
    "```\n",
    "\n",
    "When a json file is passed as a request format to the curl, Torchserve unwraps the json file from the request body. This is the reason for specifying service_envelope=body in the config.properties file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[\r\n",
      "  [\r\n",
      "    [\r\n",
      "      0.004570948731989492,\r\n",
      "      0.006216969640322402,\r\n",
      "      0.008197565423679522,\r\n",
      "      0.009563574612830427,\r\n",
      "      0.008999274832810742,\r\n",
      "      0.009673474804303854,\r\n",
      "      0.007599905146155397,\r\n",
      "      0.00636138087221357,\r\n",
      "      0.005768828729217899,\r\n",
      "      0.004394465747976554,\r\n",
      "      0.004948218056579564,\r\n",
      "      0.005273460629510146,\r\n",
      "      0.005523799690682735,\r\n",
      "      0.007789356618988726,\r\n",
      "      0.008759363533045739,\r\n",
      "      0.004304805440696481,\r\n",
      "      0.010970579124389682,\r\n",
      "      0.0032484391676092287,\r\n",
      "      0.005998033079490753,\r\n",
      "      0.003754366000510472,\r\n",
      "      0.002765290919421939,\r\n",
      "      0.0043140862178245466,\r\n",
      "      0.001400857504198272,\r\n",
      "      0.004841846660876866,\r\n",
      "      0.0006374841493763042,\r\n",
      "      0.001855854010034871,\r\n",
      "      -0.0008280458282478836,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.00166251588071497,\r\n",
      "      0.0044437916933807,\r\n",
      "      0.012387840712028125,\r\n",
      "      0.009450844412298704,\r\n",
      "      0.016143820999121934,\r\n",
      "      0.007797502488838184,\r\n",
      "      0.01394224080820749,\r\n",
      "      0.007557430593412898,\r\n",
      "      0.005479090725005886,\r\n",
      "      0.00975132063969513,\r\n",
      "      0.004764407589221943,\r\n",
      "      0.007292147866982278,\r\n",
      "      0.011797999173224124,\r\n",
      "      0.006462685044317422,\r\n",
      "      0.0033832139391885693,\r\n",
      "      0.009225059436106376,\r\n",
      "      0.0016750701226780703,\r\n",
      "      0.007362305264288119,\r\n",
      "      0.005270057995809192,\r\n",
      "      0.005453598390261765,\r\n",
      "      0.004342725904924113,\r\n",
      "      0.005856133423715095,\r\n",
      "      0.012168384816778567,\r\n",
      "      0.009902719550207576,\r\n",
      "      0.009813113104687824,\r\n",
      "      0.0034427582781191165,\r\n",
      "      0.002292428478682038,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.011528255374329572,\r\n",
      "      0.009146988980595707,\r\n",
      "      0.022265419756328467,\r\n",
      "      0.017558217187278263,\r\n",
      "      0.02477055483346851,\r\n",
      "      0.0214126935822772,\r\n",
      "      0.014453379925406693,\r\n",
      "      0.009229923687803773,\r\n",
      "      0.01016500161212654,\r\n",
      "      0.006547578386614475,\r\n",
      "      0.03472136349734433,\r\n",
      "      0.015304972271039665,\r\n",
      "      0.007053292398788774,\r\n",
      "      0.017017104469952547,\r\n",
      "      0.000428880443110661,\r\n",
      "      -0.03446447087290062,\r\n",
      "      -0.028986433652493634,\r\n",
      "      -0.017016031894781198,\r\n",
      "      -0.0177712584787139,\r\n",
      "      0.016880202827783346,\r\n",
      "      0.008659977533168361,\r\n",
      "      0.010573380772576567,\r\n",
      "      0.016392586524799916,\r\n",
      "      0.013665163896483002,\r\n",
      "      0.009255274713238825,\r\n",
      "      0.004815627223860795,\r\n",
      "      0.0032046895568865687,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.0064381901649377725,\r\n",
      "      0.005482977636637665,\r\n",
      "      0.014281822341768433,\r\n",
      "      0.014896173801426297,\r\n",
      "      0.02243572942956626,\r\n",
      "      0.015215458663741074,\r\n",
      "      0.031213338824478135,\r\n",
      "      0.02189213588991701,\r\n",
      "      0.018180598309071448,\r\n",
      "      0.03125694736792799,\r\n",
      "      0.05227424653471739,\r\n",
      "      0.02227170720300342,\r\n",
      "      0.010566675257167063,\r\n",
      "      0.005880461233122001,\r\n",
      "      0.0073714263085994745,\r\n",
      "      -0.05819867982754784,\r\n",
      "      -0.07052216778702386,\r\n",
      "      -0.014321804485030407,\r\n",
      "      -0.010228087026138416,\r\n",
      "      -0.021572370099731973,\r\n",
      "      0.009291820303892216,\r\n",
      "      -0.007033522522145339,\r\n",
      "      0.021310003639157426,\r\n",
      "      0.015776696984352967,\r\n",
      "      0.018816130371453497,\r\n",
      "      0.014796157049598923,\r\n",
      "      0.007133092722335582,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.01288908211444727,\r\n",
      "      0.009241330239921266,\r\n",
      "      0.01903574208549175,\r\n",
      "      0.007234016161703008,\r\n",
      "      0.018466540428849768,\r\n",
      "      0.005577407347496944,\r\n",
      "      0.02317224185981127,\r\n",
      "      0.020410131134924972,\r\n",
      "      0.004391232120978804,\r\n",
      "      -0.0014250168106010638,\r\n",
      "      0.038245516542454866,\r\n",
      "      0.005503564252868609,\r\n",
      "      -0.013327790354209718,\r\n",
      "      -0.017123156293358612,\r\n",
      "      -0.38494986552341354,\r\n",
      "      -0.5038683843682443,\r\n",
      "      -0.32766597295590955,\r\n",
      "      -0.3410664061572259,\r\n",
      "      -0.23823562175775412,\r\n",
      "      0.013047128190147151,\r\n",
      "      -0.0026851381924494887,\r\n",
      "      -0.03269753899956235,\r\n",
      "      -0.012143627906102036,\r\n",
      "      0.007277866769707327,\r\n",
      "      0.005280617396966189,\r\n",
      "      0.005043191383860095,\r\n",
      "      0.0016267561451155906,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.004671167814663807,\r\n",
      "      0.00666956644329794,\r\n",
      "      0.017121951435288316,\r\n",
      "      0.013696786315898067,\r\n",
      "      0.014920347300289684,\r\n",
      "      0.003035267671205596,\r\n",
      "      0.01868255532793876,\r\n",
      "      0.016070625840328073,\r\n",
      "      0.01886351521286884,\r\n",
      "      -0.03419997199515245,\r\n",
      "      0.03624187611112635,\r\n",
      "      -0.37946019218526233,\r\n",
      "      -0.27036209063999617,\r\n",
      "      0.036982165941239535,\r\n",
      "      0.13571687277445446,\r\n",
      "      -0.17258095231920142,\r\n",
      "      0.2868882941114911,\r\n",
      "      -0.0029589213203174984,\r\n",
      "      -0.3049862261393523,\r\n",
      "      -0.1545121068058157,\r\n",
      "      -0.00911779562390712,\r\n",
      "      0.0007181363313936802,\r\n",
      "      0.0019109263870262852,\r\n",
      "      -0.007108051900508097,\r\n",
      "      0.01071538155320752,\r\n",
      "      0.018331707995372135,\r\n",
      "      0.007118541518524465,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.011730132121924135,\r\n",
      "      0.006826550904781909,\r\n",
      "      0.02400405509100923,\r\n",
      "      0.019528626451574327,\r\n",
      "      0.0262460482968153,\r\n",
      "      0.004725325524843718,\r\n",
      "      0.011773783807310551,\r\n",
      "      0.0014583252908695022,\r\n",
      "      0.025192076848896704,\r\n",
      "      0.0386878656321084,\r\n",
      "      -0.014956023786495569,\r\n",
      "      -0.26154688891913713,\r\n",
      "      -0.059379918346905036,\r\n",
      "      -0.2145426784502667,\r\n",
      "      -0.18480000052723788,\r\n",
      "      0.1823583417229497,\r\n",
      "      0.295032362564659,\r\n",
      "      -0.1469518144799008,\r\n",
      "      -0.37042445313348005,\r\n",
      "      -0.22677560457048726,\r\n",
      "      -0.0023366662614289976,\r\n",
      "      0.00424747761564603,\r\n",
      "      -0.012314807468860952,\r\n",
      "      -0.0006275747681590516,\r\n",
      "      0.009095566738055002,\r\n",
      "      0.010577039934850442,\r\n",
      "      0.0021456214370207767,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.006522710992560629,\r\n",
      "      0.006658460491438304,\r\n",
      "      0.011681141910031003,\r\n",
      "      0.01385473038303331,\r\n",
      "      0.017837691311278624,\r\n",
      "      0.006804051668131839,\r\n",
      "      0.014004743748695307,\r\n",
      "      0.013872584350285332,\r\n",
      "      -0.024564484071584135,\r\n",
      "      -0.041963559076796705,\r\n",
      "      -0.034551623910865435,\r\n",
      "      -0.024959728547101028,\r\n",
      "      0.00453889674678142,\r\n",
      "      0.02602897629397592,\r\n",
      "      -0.09770229904452654,\r\n",
      "      -0.0078572486893087,\r\n",
      "      -0.017651245373454694,\r\n",
      "      -0.0013648177977099317,\r\n",
      "      -0.15123346128201384,\r\n",
      "      -0.15900134281248063,\r\n",
      "      0.047439669621457285,\r\n",
      "      0.018941404525559525,\r\n",
      "      -0.02981872755921296,\r\n",
      "      -0.01172369828767206,\r\n",
      "      0.0048622392441007205,\r\n",
      "      0.009659960490814933,\r\n",
      "      0.007569256344790838,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.009820465826493659,\r\n",
      "      0.010157525421855,\r\n",
      "      0.023513310376312675,\r\n",
      "      0.017823668566007252,\r\n",
      "      0.014352911426498664,\r\n",
      "      0.006792569818753856,\r\n",
      "      0.01709471817027299,\r\n",
      "      0.022002334336862633,\r\n",
      "      0.011678225643802383,\r\n",
      "      -0.07573987937481919,\r\n",
      "      -0.05761077882024471,\r\n",
      "      -0.06535464771581313,\r\n",
      "      -0.08852594565296287,\r\n",
      "      -0.08690353979606168,\r\n",
      "      -0.038970146009268465,\r\n",
      "      -0.014092121919642812,\r\n",
      "      -0.05026295528427675,\r\n",
      "      -0.018569489865643073,\r\n",
      "      0.10833790599616444,\r\n",
      "      -0.06861286943571396,\r\n",
      "      -0.16792157639925268,\r\n",
      "      -0.005195128018432535,\r\n",
      "      -0.04163920251519448,\r\n",
      "      -0.0071293679421926175,\r\n",
      "      0.01481990402102848,\r\n",
      "      0.00892140817543594,\r\n",
      "      0.0041566054329483515,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.004465642435917224,\r\n",
      "      0.0068508854554447845,\r\n",
      "      0.0129028312965937,\r\n",
      "      0.013639461034673374,\r\n",
      "      -0.00032053191313815665,\r\n",
      "      0.003910277520708287,\r\n",
      "      0.009035449300533663,\r\n",
      "      0.009675447061916552,\r\n",
      "      0.0184014115628898,\r\n",
      "      -0.026809595920222723,\r\n",
      "      -0.016714827848266587,\r\n",
      "      -0.04334933136874045,\r\n",
      "      -0.016360022271701663,\r\n",
      "      -0.007439369004492128,\r\n",
      "      0.015627533034300974,\r\n",
      "      -0.05196060531288124,\r\n",
      "      -0.07462407774966506,\r\n",
      "      -0.040328363055968,\r\n",
      "      0.16436907704679576,\r\n",
      "      -0.10282470891172335,\r\n",
      "      -0.15888629232910523,\r\n",
      "      -0.005633529148818552,\r\n",
      "      -0.0327755964983166,\r\n",
      "      -0.010684832766747128,\r\n",
      "      0.017376999411916724,\r\n",
      "      0.0068671187821933155,\r\n",
      "      0.001322469861080909,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.009060879427516098,\r\n",
      "      0.013138363692372975,\r\n",
      "      0.027552776784759488,\r\n",
      "      0.008328838024912442,\r\n",
      "      0.03330297116907518,\r\n",
      "      -0.005269810920320149,\r\n",
      "      0.016500515801182208,\r\n",
      "      -0.012387738162166283,\r\n",
      "      -0.010385546090051406,\r\n",
      "      -0.012111983065996262,\r\n",
      "      -0.013766926982694555,\r\n",
      "      -0.02419507832753571,\r\n",
      "      -0.02106385595631272,\r\n",
      "      0.04478263421842224,\r\n",
      "      -0.05015260717059383,\r\n",
      "      -0.14608027807901755,\r\n",
      "      0.020168070906765,\r\n",
      "      -0.1768984357481869,\r\n",
      "      -0.026853884992248167,\r\n",
      "      0.048344315951360725,\r\n",
      "      -0.13650171232571318,\r\n",
      "      -0.041908175553481294,\r\n",
      "      -0.012802079822805831,\r\n",
      "      0.010229497261795494,\r\n",
      "      0.023323646788395404,\r\n",
      "      0.0023560714156533194,\r\n",
      "      0.0034970590866629713,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.004333510430861486,\r\n",
      "      0.010170070415895054,\r\n",
      "      0.013534043401616801,\r\n",
      "      0.019568579922536897,\r\n",
      "      0.003896066812369829,\r\n",
      "      -0.002344431415341743,\r\n",
      "      -0.005318073005144471,\r\n",
      "      -0.00668411363833911,\r\n",
      "      0.005492772288872441,\r\n",
      "      -0.01742178603003337,\r\n",
      "      -0.02583245209149884,\r\n",
      "      -0.0224758791407631,\r\n",
      "      -0.0024575710398865073,\r\n",
      "      0.012312911409957859,\r\n",
      "      -0.12523219571299,\r\n",
      "      0.06440137832473761,\r\n",
      "      -0.10151132053715228,\r\n",
      "      0.3272276797863912,\r\n",
      "      -0.22650441230843657,\r\n",
      "      -0.09795739349381771,\r\n",
      "      -0.06038186892593042,\r\n",
      "      -0.07863148342432824,\r\n",
      "      0.006171918741675569,\r\n",
      "      0.007392134409629039,\r\n",
      "      0.015564094506721438,\r\n",
      "      0.00870364130577883,\r\n",
      "      0.0013642514536805228,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.007275359844097868,\r\n",
      "      0.014084568700328641,\r\n",
      "      0.013559615657054868,\r\n",
      "      0.027847544725258733,\r\n",
      "      0.0037534519992355807,\r\n",
      "      -0.01100678432395469,\r\n",
      "      -0.035677531475821776,\r\n",
      "      -0.01741305646985304,\r\n",
      "      -0.028202377881469346,\r\n",
      "      -0.01659200024892211,\r\n",
      "      -0.025004752715671655,\r\n",
      "      0.03940142799353865,\r\n",
      "      -0.006935097770278363,\r\n",
      "      -0.07919714562320493,\r\n",
      "      0.09328278306479532,\r\n",
      "      -0.1702641890911152,\r\n",
      "      0.08847574553544772,\r\n",
      "      -0.02530949866205925,\r\n",
      "      -0.4156587049439625,\r\n",
      "      -0.05348891696170698,\r\n",
      "      -0.09691602330853981,\r\n",
      "      -0.02290306688952313,\r\n",
      "      0.07867733225536148,\r\n",
      "      0.008387871009833058,\r\n",
      "      0.03103757514831976,\r\n",
      "      0.0095476041086751,\r\n",
      "      0.0048975684714045445,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.005270409208072307,\r\n",
      "      0.012425094744783004,\r\n",
      "      0.017236165129366574,\r\n",
      "      0.022829355229962666,\r\n",
      "      0.006738329199251001,\r\n",
      "      0.019327303688831485,\r\n",
      "      -0.009565645998398029,\r\n",
      "      0.010368217162211011,\r\n",
      "      0.0005331798494046443,\r\n",
      "      -0.013186581993959539,\r\n",
      "      -0.023845998166089816,\r\n",
      "      0.012288673778235207,\r\n",
      "      -0.0013052097989707501,\r\n",
      "      -0.09691418233919591,\r\n",
      "      0.23162136816282064,\r\n",
      "      -0.11681173579335637,\r\n",
      "      -0.11046197973382482,\r\n",
      "      -0.2723711309548866,\r\n",
      "      -0.1935074346224829,\r\n",
      "      -0.05611027584940715,\r\n",
      "      -0.09813431344224743,\r\n",
      "      0.048928590674281236,\r\n",
      "      0.005389681395266223,\r\n",
      "      0.00966407269460025,\r\n",
      "      0.018803857478553475,\r\n",
      "      0.007985762394404416,\r\n",
      "      0.0021901347381123927,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.0073801918992191145,\r\n",
      "      0.019572452679726005,\r\n",
      "      0.011062355646768891,\r\n",
      "      0.02619356301864183,\r\n",
      "      0.007427339449517372,\r\n",
      "      0.0032789556783711323,\r\n",
      "      -0.007245173321052202,\r\n",
      "      0.004624768185220014,\r\n",
      "      -0.01157116458837452,\r\n",
      "      0.004316197656264229,\r\n",
      "      -0.026239501539836643,\r\n",
      "      -0.09986898502654395,\r\n",
      "      0.021094888763720617,\r\n",
      "      -0.09874684614845193,\r\n",
      "      -0.2379328647898273,\r\n",
      "      -0.11023317481481096,\r\n",
      "      -0.08547650014675423,\r\n",
      "      0.28544968332495346,\r\n",
      "      -0.0758757730426992,\r\n",
      "      -0.06974352161399618,\r\n",
      "      0.01234133667061945,\r\n",
      "      0.0377634721686999,\r\n",
      "      0.022022240659507912,\r\n",
      "      0.02028501969632055,\r\n",
      "      0.012077822718493867,\r\n",
      "      0.00025287162047371033,\r\n",
      "      0.0028423975463497705,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.002840066565118678,\r\n",
      "      0.0060756999462100785,\r\n",
      "      0.017424373964686237,\r\n",
      "      0.0239305886228527,\r\n",
      "      0.01743923021604954,\r\n",
      "      0.017304977069282267,\r\n",
      "      0.02598198955914301,\r\n",
      "      0.01950632354675457,\r\n",
      "      -0.029749493862308386,\r\n",
      "      0.0530237593076662,\r\n",
      "      -0.03791460680441433,\r\n",
      "      -0.16601164745050107,\r\n",
      "      0.03912921985939226,\r\n",
      "      -0.6633131189366827,\r\n",
      "      -0.17481853672902856,\r\n",
      "      -0.15054703113067366,\r\n",
      "      0.0554867016565209,\r\n",
      "      -0.0294025603636392,\r\n",
      "      -0.008018408338302911,\r\n",
      "      0.020051017678466686,\r\n",
      "      0.015712001988193513,\r\n",
      "      0.004161804977203034,\r\n",
      "      0.009324703404921557,\r\n",
      "      0.012510240105369727,\r\n",
      "      0.013918036176403742,\r\n",
      "      0.0014513172691919237,\r\n",
      "      -0.008265808778806139,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.011261885810927878,\r\n",
      "      0.00648306037813756,\r\n",
      "      0.008503841305111438,\r\n",
      "      0.01067958899927799,\r\n",
      "      0.015129837356538115,\r\n",
      "      -0.0006185694328050059,\r\n",
      "      0.0004094197188552838,\r\n",
      "      0.03133174804604566,\r\n",
      "      -0.031818992346588144,\r\n",
      "      -0.0010702996689752,\r\n",
      "      -0.10024810616747404,\r\n",
      "      -0.029930771999774123,\r\n",
      "      -0.6482274958725135,\r\n",
      "      -0.37763689415245233,\r\n",
      "      -0.4337522192955517,\r\n",
      "      -0.03636643275783212,\r\n",
      "      -0.013711053520537976,\r\n",
      "      0.05675663816595256,\r\n",
      "      0.05643754533054348,\r\n",
      "      0.002132286193979714,\r\n",
      "      0.03655338811187708,\r\n",
      "      0.01413799719771283,\r\n",
      "      0.02346467057610677,\r\n",
      "      0.021753613895440782,\r\n",
      "      0.022771733623495886,\r\n",
      "      0.007055280190183856,\r\n",
      "      -0.00433707703043476,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.0017600621711631023,\r\n",
      "      0.0011219999785941845,\r\n",
      "      0.013428492291544209,\r\n",
      "      0.01759714986589126,\r\n",
      "      0.024533402972081324,\r\n",
      "      0.020859147549965297,\r\n",
      "      0.029007089567570515,\r\n",
      "      0.03315024829088432,\r\n",
      "      -0.12486206955625014,\r\n",
      "      -0.10817762439536302,\r\n",
      "      0.004958701270978797,\r\n",
      "      -0.8515792949751524,\r\n",
      "      -0.6992899125245882,\r\n",
      "      0.05685671291518604,\r\n",
      "      -0.0219250300600306,\r\n",
      "      -0.018604185126784148,\r\n",
      "      0.05339881694331926,\r\n",
      "      0.039366949753155356,\r\n",
      "      -0.05227341623355211,\r\n",
      "      -0.062489110470307745,\r\n",
      "      -0.005787278674923421,\r\n",
      "      -0.008131731954701762,\r\n",
      "      0.003225139629114342,\r\n",
      "      0.02509357830792854,\r\n",
      "      0.017987539758127294,\r\n",
      "      0.0004527421687479845,\r\n",
      "      -0.0009731599067520569,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.012173792680898353,\r\n",
      "      0.0028796247524366723,\r\n",
      "      0.012965951358750342,\r\n",
      "      0.019137056799449076,\r\n",
      "      0.011522835532896514,\r\n",
      "      0.012565033553652509,\r\n",
      "      0.014996321169801196,\r\n",
      "      -0.08070841727663541,\r\n",
      "      -0.153396267823572,\r\n",
      "      0.14678779481380178,\r\n",
      "      -0.7700742584135195,\r\n",
      "      -0.447496532730772,\r\n",
      "      -0.4290962984608853,\r\n",
      "      -0.23181639868199796,\r\n",
      "      -0.04026972631632491,\r\n",
      "      0.05150747488289929,\r\n",
      "      0.07160880032914727,\r\n",
      "      -0.03533688604268756,\r\n",
      "      -0.10970645454744385,\r\n",
      "      -0.10930210001134083,\r\n",
      "      -0.024853277249138255,\r\n",
      "      0.00822770636540953,\r\n",
      "      0.024960399021376912,\r\n",
      "      0.03249052432199244,\r\n",
      "      0.004058922196733905,\r\n",
      "      -0.0009919195605522346,\r\n",
      "      -0.003959662695278879,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.006446408571009735,\r\n",
      "      0.0015721975116701535,\r\n",
      "      0.010684784213568865,\r\n",
      "      0.020069167204513322,\r\n",
      "      0.01742693813306818,\r\n",
      "      0.009070814976329666,\r\n",
      "      -0.05182414690959381,\r\n",
      "      -0.06390323971382153,\r\n",
      "      -0.13564039059249364,\r\n",
      "      -0.554577301244361,\r\n",
      "      -0.2856855077419035,\r\n",
      "      -0.12720276872050001,\r\n",
      "      -0.6356528616990034,\r\n",
      "      0.0595639217742856,\r\n",
      "      -0.009104179006752937,\r\n",
      "      0.0030898839708612207,\r\n",
      "      -0.06931889788833766,\r\n",
      "      -0.0655000403818148,\r\n",
      "      0.014932961512568616,\r\n",
      "      -0.08919109899538519,\r\n",
      "      0.027359642165127415,\r\n",
      "      0.02510929075729112,\r\n",
      "      0.01759725841715928,\r\n",
      "      0.007466607782730732,\r\n",
      "      0.00875460983770239,\r\n",
      "      -0.0003243360079181762,\r\n",
      "      -0.00521201329564524,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.015828474583462458,\r\n",
      "      0.0068876198965653794,\r\n",
      "      0.014813772428665268,\r\n",
      "      0.018514283498910565,\r\n",
      "      0.010787938473573079,\r\n",
      "      0.001261317592306946,\r\n",
      "      -0.04906287932566751,\r\n",
      "      0.018889898381641283,\r\n",
      "      -0.42578693958079994,\r\n",
      "      -0.1636782139867584,\r\n",
      "      0.08846821425233356,\r\n",
      "      0.18242934509700673,\r\n",
      "      -0.003274506673928136,\r\n",
      "      0.06264647359468664,\r\n",
      "      -0.2258013509505491,\r\n",
      "      -0.4458349105714705,\r\n",
      "      -0.22586626697541293,\r\n",
      "      -0.5565314926963113,\r\n",
      "      -0.47274758173472153,\r\n",
      "      -0.19089266165874585,\r\n",
      "      0.007733122546716923,\r\n",
      "      0.06482986097025122,\r\n",
      "      0.022017800285519442,\r\n",
      "      0.020701821564281853,\r\n",
      "      0.007135878846140666,\r\n",
      "      0.004293818143185992,\r\n",
      "      -0.001299475499293427,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.005827066041138483,\r\n",
      "      0.0049460521601267715,\r\n",
      "      0.019525304951468998,\r\n",
      "      0.008122795649821712,\r\n",
      "      0.019879757530299275,\r\n",
      "      -0.0020521163615618925,\r\n",
      "      0.02580439896865069,\r\n",
      "      -0.052193635714182035,\r\n",
      "      0.03416748320909369,\r\n",
      "      0.16259612641043358,\r\n",
      "      0.0709530815197632,\r\n",
      "      0.06003294771526414,\r\n",
      "      -0.004392957411193872,\r\n",
      "      -0.1631386177372534,\r\n",
      "      -0.3404318814983978,\r\n",
      "      -0.047454385990442174,\r\n",
      "      0.2861510807721348,\r\n",
      "      0.05897198266960267,\r\n",
      "      -0.05910995012275236,\r\n",
      "      0.033603790991256925,\r\n",
      "      0.017537061703373536,\r\n",
      "      0.016888334721962876,\r\n",
      "      0.011253182411812288,\r\n",
      "      -0.0016834115349447913,\r\n",
      "      0.005493190270823567,\r\n",
      "      0.005668896898822112,\r\n",
      "      0.0012772967337156378,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.013529335252869324,\r\n",
      "      0.016841846066933272,\r\n",
      "      0.014358039174171331,\r\n",
      "      0.013893648644178093,\r\n",
      "      0.02422287196479451,\r\n",
      "      0.014696586735289804,\r\n",
      "      -0.007401157724708546,\r\n",
      "      0.03778438837734676,\r\n",
      "      0.16444490117462124,\r\n",
      "      -0.026853450404766548,\r\n",
      "      0.14795191807753846,\r\n",
      "      -0.0644245181328066,\r\n",
      "      -0.0007332767794627947,\r\n",
      "      0.004811936860322093,\r\n",
      "      -0.13623605262262742,\r\n",
      "      0.059491212951517124,\r\n",
      "      -0.10643248638580079,\r\n",
      "      0.030842018452283935,\r\n",
      "      0.026392661128086168,\r\n",
      "      0.03914788424169654,\r\n",
      "      0.04801307621944063,\r\n",
      "      0.022478460848075567,\r\n",
      "      0.03014489052008241,\r\n",
      "      0.01929912142871645,\r\n",
      "      0.008045379728884198,\r\n",
      "      0.0012503587655002867,\r\n",
      "      -0.000991857550283674,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.0046231698212737616,\r\n",
      "      0.010020522315935169,\r\n",
      "      0.01716136178250389,\r\n",
      "      0.01627290827074845,\r\n",
      "      0.012153300438049902,\r\n",
      "      0.01527476071228186,\r\n",
      "      0.006974948616167474,\r\n",
      "      0.006645510331932922,\r\n",
      "      0.010906953714952188,\r\n",
      "      -0.05196741550705083,\r\n",
      "      0.014580668981942446,\r\n",
      "      0.002166179940274503,\r\n",
      "      -0.023983937003606945,\r\n",
      "      -0.04372417390620132,\r\n",
      "      -0.04247351536613899,\r\n",
      "      -0.009858924259392879,\r\n",
      "      0.0486776889132781,\r\n",
      "      0.05061761727785411,\r\n",
      "      0.040812162022730566,\r\n",
      "      0.002770689593711723,\r\n",
      "      0.017428846169941357,\r\n",
      "      0.011267520248448341,\r\n",
      "      0.019473539586219276,\r\n",
      "      0.003239538179312084,\r\n",
      "      0.01062991040926208,\r\n",
      "      0.009922420456827273,\r\n",
      "      0.0042801603623850125,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.008073670690570967,\r\n",
      "      0.007712105286267007,\r\n",
      "      0.005741633327422778,\r\n",
      "      0.005971192372787415,\r\n",
      "      0.010885811170536242,\r\n",
      "      -0.008894670832835735,\r\n",
      "      -0.004672381509653262,\r\n",
      "      -0.0138461871005014,\r\n",
      "      -0.05105479710234698,\r\n",
      "      -0.06948789603437013,\r\n",
      "      -0.06614005124999449,\r\n",
      "      -0.06779717151632161,\r\n",
      "      -0.05812602690234497,\r\n",
      "      -0.020652205184373953,\r\n",
      "      -0.008073019530454986,\r\n",
      "      0.02168627230638423,\r\n",
      "      0.025676786176107882,\r\n",
      "      0.015063618311900381,\r\n",
      "      0.002983815130840771,\r\n",
      "      0.010908992413900387,\r\n",
      "      0.007796246647514373,\r\n",
      "      0.0066128255232435875,\r\n",
      "      0.013132494257238274,\r\n",
      "      0.008734255447328705,\r\n",
      "      0.004473871753689314,\r\n",
      "      0.0006531380846003495,\r\n",
      "      -0.0014991191337850656,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.004735396801109709,\r\n",
      "      0.0015361730738590249,\r\n",
      "      0.00747965330096188,\r\n",
      "      0.006853575452610601,\r\n",
      "      0.010822806386335919,\r\n",
      "      0.008211475193301938,\r\n",
      "      0.0021726594639988575,\r\n",
      "      -0.0065398763724838944,\r\n",
      "      0.001821248411827084,\r\n",
      "      -0.018543311795896134,\r\n",
      "      -0.02108739996165117,\r\n",
      "      -0.015464512154839023,\r\n",
      "      -0.011346785092969982,\r\n",
      "      0.0027885896576798092,\r\n",
      "      -0.0003556658464629098,\r\n",
      "      0.00914765423888431,\r\n",
      "      0.013769058489143065,\r\n",
      "      0.013925278165182246,\r\n",
      "      0.020668979415445467,\r\n",
      "      0.02117543704976742,\r\n",
      "      0.015437734267273883,\r\n",
      "      0.0010211567904162655,\r\n",
      "      0.006025937073207437,\r\n",
      "      0.0061858522678138765,\r\n",
      "      0.007809518910250496,\r\n",
      "      0.006282688201438807,\r\n",
      "      0.0032008943720398903,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      0.0027774170334228265,\r\n",
      "      0.002159801521315026,\r\n",
      "      0.0009954783260103662,\r\n",
      "      -0.0023597541230223795,\r\n",
      "      -0.0019994855712765847,\r\n",
      "      0.0006750465371489075,\r\n",
      "      0.0006236063198256565,\r\n",
      "      0.006512479472848459,\r\n",
      "      0.008345381579533946,\r\n",
      "      0.0009539414736513663,\r\n",
      "      -0.0007099559153227343,\r\n",
      "      -0.00011675720748663704,\r\n",
      "      -0.0011169547784155123,\r\n",
      "      0.001793534973043206,\r\n",
      "      -0.0019099637405916834,\r\n",
      "      0.0015855262453375175,\r\n",
      "      0.0036409566641309194,\r\n",
      "      -0.0005390934328924084,\r\n",
      "      0.0064513327328557446,\r\n",
      "      0.0027735805355367277,\r\n",
      "      0.006060840367244276,\r\n",
      "      0.000359165926315527,\r\n",
      "      0.0018643897471817563,\r\n",
      "      -0.0008303191079628302,\r\n",
      "      -0.0024594973537835877,\r\n",
      "      -0.0017738576926115562,\r\n",
      "      -0.0007076670305583287,\r\n",
      "      -0.0\r\n",
      "    ],\r\n",
      "    [\r\n",
      "      -0.0,\r\n",
      "      -0.0,\r\n",
      "      0.0005382485914412182,\r\n",
      "      -0.0006324885664017992,\r\n",
      "      -0.003595975043089762,\r\n",
      "      -0.0018980114805717792,\r\n",
      "      -0.0005749303948698967,\r\n",
      "      0.0012654955920759015,\r\n",
      "      0.0036969897692216216,\r\n",
      "      0.000977110922868114,\r\n",
      "      -0.0003167563284092459,\r\n",
      "      -0.0005752726948934128,\r\n",
      "      0.000789864852287303,\r\n",
      "      0.002705500072887267,\r\n",
      "      -0.00040143920665009533,\r\n",
      "      0.0011896338595401026,\r\n",
      "      0.0002241121980320825,\r\n",
      "      -0.00025305534684833724,\r\n",
      "      -6.698087605655334e-05,\r\n",
      "      -0.0,\r\n",
      "      -0.0,\r\n",
      "      -0.0,\r\n",
      "      -0.0,\r\n",
      "      -0.0,\r\n",
      "      -0.0,\r\n",
      "      -0.0,\r\n",
      "      -0.0,\r\n",
      "      -0.0\r\n",
      "    ]\r\n",
      "  ]\r\n",
      "]"
     ]
    }
   ],
   "source": [
    "#curl command to make an Explanation Request and the response is as below:\n",
    "#mnis_ts.json file contains the input for the inference request\n",
    "!curl -H \"Content-Type: application/json\" --data @examples/image_classifier/mnist/mnist_ts.json http://127.0.0.1:8080/explanations/mnist_explain"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The above explanation response is present in the mnist_response.json file. From the MNIST_Response.json file the attributions key-value pair is loaded"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "input_file=open('./mnist_response.json', 'r')\n",
    "input_json = json.load(input_file)\n",
    "attributions = input_json['explanations']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "img_path=\"./examples/image_classifier/mnist/test_data/2.png\"\n",
    "inp_image = Image.open(img_path)\n",
    "inp_image = ToTensor()(inp_image).unsqueeze(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For the captum visual insights, we need to pass the Input Image and the Attributions as arguments. The input type should be in the form of a numpy array for both these arguments, since the visualize_image_attr method only support numpy array data type."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "attributions = np.array(attributions)\n",
    "inp_image = np.array(inp_image)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Attributions Shape : (1, 1, 28, 28)\n",
      "Input Image Shape : (1, 1, 28, 28)\n"
     ]
    }
   ],
   "source": [
    "#Printing the shape of attributions and inp_image\n",
    "print(\"Attributions Shape :\", attributions.shape)\n",
    "print(\"Input Image Shape :\", inp_image.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Reorient the shape to render the visualization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "inp_image = inp_image.reshape((28,28,1))\n",
    "attributions = attributions.reshape((28,28,1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Displaying the Original Image to show the changes with captum insights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9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3f1vSOknLGuij67n7Jkl7Dlu8TNLa7P5ajf/n6bic3rqCu+9y92ez+yOSDs4s3ehzl+irEU2E/zRJr054vEPdNeW3S/qemT1jZgNNNzOJOdm06QenT5/dcD+HK5y5uZMOm1m6a567dma8rloT4Z9s9p9uGnJY4u4XSvqQpBuyl7doTUszN3fKJDNLd4V2Z7yuWhPh3yHp9AmP3ydpZwN9TMrdd2a3w5LWq/tmH959cJLU7Ha44X7e0U0zN082s7S64Lnrphmvmwj/FknnmNmZZjZN0ickbWigjyOY2YzsjRiZ2QxJV6j7Zh/eIGlldn+lpEcb7OUQ3TJzc97M0mr4ueu2Ga8b+ZBPNpTxZUk9kta4+992vIlJmNmva/xsL41PYvqNJnszs4ckXabxb33tlvRZSY9I+pakeZJekfQxd+/4G285vV2m8Zeu78zcfPAau8O9XSrpSUlbJY1li2/T+PV1Y89doq/lauB54xN+QFB8wg8IivADQRF+ICjCDwRF+IGgCD8QFOEHgiL8QFD/ByuY9vHOWBUhAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.image as mpimg\n",
    "img = mpimg.imread('./examples/image_classifier/mnist/test_data/2.png')\n",
    "imgplot = plt.imshow(img)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVgAAAF1CAYAAACtXvKoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xm0XWWZ5/Hfc+6Y3IQMgEBICARCIMqUArEoFRxKGXoJpahUg4JTF9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ACELAAkAQAhYAghCwABCEgAWAIP8fiUyae/rHgUkAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x432 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "(<Figure size 432x432 with 2 Axes>,\n",
       " <matplotlib.axes._subplots.AxesSubplot at 0x7f29c634bd30>)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "viz.visualize_image_attr(attributions,\n",
    "                             inp_image,method=\"blended_heat_map\",sign=\"all\",\n",
    "                          show_colorbar=True, title=\"Overlayed Integrated Gradients\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
